package ${cfg.baseControllerPackage};

import com.mryt.admin.domain.result.CommonVo;
import com.mryt.dt.base.PageReq;
import com.mryt.api.domain.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
import ${cfg.baseDbBeanPackage}.domain.${table.beanName};
import ${cfg.baseServicePackage}.${table.beanName}Service;


@RestController
@RequestMapping("${cfg.baseControllerPath}")
@Slf4j
public class ${table.beanName}Controller {

    @Autowired
    private ${table.beanName}Service service;

    @PostMapping(value = "/page")
    public Object recordPage(@RequestBody PageReq<${table.beanName}> req) {
    if (Objects.isNull(req)) {
    log.info("query page of stock, stockVo is null");
    return CommonVo.Builder.FAIL("参数不能为空");
    }
    return ApiResult.success(service.page(req));
    }

    @PostMapping(value = "/save")
    public Object saveOrUpdate(@RequestBody ${table.beanName} req) {
    if (Objects.isNull(req)) {
    log.info("query page of stock, stockVo is null");
    return CommonVo.Builder.FAIL("参数不能为空");
    }
    return service.save(req);
    }

    @PostMapping(value = "/get")
    public Object get(@RequestBody ${table.beanName} req) {
    if (Objects.isNull(req)) {
    log.info("query page of stock, stockVo is null");
    return CommonVo.Builder.FAIL("参数不能为空");
    }
    return ApiResult.success(service.getById(req.getId()));
    }


    @PostMapping(value = "/enable")
    public Object enable(@RequestBody ${table.beanName} req) {
    if (Objects.isNull(req)) {
    log.info("query page of stock, stockVo is null");
    return CommonVo.Builder.FAIL("参数不能为空");
    }
    return service.enable(req.getId(), req.getStatus());
    }




}
